package com.ryskoo.controller.dinnertable;

import com.ryskoo.catering.dinnertabletype.domain.DinnerTableTypePO;
import com.ryskoo.catering.dinnertabletype.service.IDinnerTableTypeService;
import com.ryskoo.customer.vendor.domain.VendorPO;
import com.ryskoo.customer.vendor.service.IVendorService;
import com.ryskoo.framework.core.bean.QueryConditionEnum;
import com.ryskoo.framework.core.bean.QueryMessageDTO;
import com.ryskoo.framework.core.bean.ReturnMessageDTO;
import com.ryskoo.framework.core.controller.BasicHandler;
import com.ryskoo.framework.core.utils.LoginUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/vendor/dinnertabletype")
public class DinnerTableTypeController extends BasicHandler<DinnerTableTypePO> {

    private static final String TEMPLATE_PATH = "system/dinnertabletype";

    private static final String MODULE_NAME = "DinnerTableType";

    /**
     * 构造方法
     */
    public DinnerTableTypeController() {
        super(TEMPLATE_PATH,MODULE_NAME);
    }
    
    private IDinnerTableTypeService dinnerTableTypeService;
    
    @Autowired
    private IVendorService vendorService;


    @Autowired
    public void setService(IDinnerTableTypeService dinnerTableTypeService) {
        this.dinnerTableTypeService = dinnerTableTypeService;
        super.setService(dinnerTableTypeService);
    }

    /**
     * 构建查询条件
     * @param qm
     */
    @Override
    protected void buildQueryMessage(QueryMessageDTO qm) {
        qm.addCondition("vendorUuid", QueryConditionEnum.EQ.name(), LoginUtil.getLoginVendorUuid());
    }

    /**
     * 重写桌台类型的添加方法，把vendorName保存进去
     * @param po
     *            新增的对象 {@link DinnerTableTypePO}
     * @return
     */
    @Override
    @PostMapping("/add")
    @ResponseBody
    public ReturnMessageDTO add(@RequestBody DinnerTableTypePO po) {
        VendorPO vendor = LoginUtil.getLoginVendorModel();
        po.setVendorUuid(vendor.getUuid());
        po.setVendorName(vendor.getVendorName());
        ReturnMessageDTO returnMessageDTO = super.add(po);
        return returnMessageDTO;
    }

}
